home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
tcclib.zip
/
DEMO2.C
< prev
next >
Wrap
Text File
|
1989-02-11
|
2KB
|
104 lines
/**************************************************************
WindowListerDemo
**************************************************************/
#include "tcclib.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mem.h>
#include <conio.h>
typedef struct {
char Path[64];
char Name[13];
long Size;
} FileRec;
FileRec File[100];
int NumRecs = 80;
int StoreFile( FileStruc *fp, char *s )
/* support function for ScanTree */
{
static int count = 0;
if ( count < 80 ) {
strcpy( File[count].Name, FileName( fp ) );
strcpy( File[count].Path, s );
File[count].Size = fp->Size;
count++;
}
return( 1 );
}
void DisplayDemo( int ndx )
{
char s[64];
sprintf( s, "%s%s", File[ndx].Path, File[ndx].Name );
SayF("%-32s %8ld", s, File[ndx].Size );
}
void ClearScreenDemo( void )
{
BlockErase( 20, 5, 60, 20 );
}
Compare( FileRec *a, FileRec *b )
{
if ( 0 != strcmp( a->Path, b->Path ) )
return( strcmp( a->Path, b->Path ) );
return( strcmp( a->Name, b->Name) );
}
int CharHandlerDemo( int ch, int ndx, int line )
/* note that this does not have to handle the ESC key, since we told
WindowLister to exit when that key is pressed.
Note: The "line" parameter is not used in this demo function. It is
only needed if you want to determine where (on the screen) the
item is that is currently highlighted.
*/
{
char temp[10];
int i = line; /* this is to get rid of the warning message */
switch( ch ) {
case F1:
Accept( 15, 23, "How many to jump (may be negative) : ", temp, 8 );
i = atoi( temp );
BlockErase( 15, 23, 65, 23 );
if ( ndx + i > NumRecs || ndx + i < 0 )
return( ndx );
return( ndx + i );
case F4:
qsort( &File, NumRecs, sizeof( FileRec ), Compare );
return( ndx );
case DEL:
for (i=ndx; i<NumRecs; ++i)
memcpy( &File[i], &File[i+1], sizeof( FileRec ) );
NumRecs--;
return( ndx );
}
return( ndx ); /* just in case the key wasn't one of the above */
}
void WindowListerDemo()
{
char Drive[5];
clrscr();
Accept( 5, 5, "Drive : ", Drive, 1 );
strcat( Drive, ":\\" );
AtSay( 30, 10, "Scanning for files ... " );
ScanTree( Drive, "*.*", StoreFile );
ExplodeBox( 19, 4, 61, 21 );
Center( 25, "F1=Jump F4=Sort DEL=Delete ESC=Quit" );
WindowLister( 20, 5, 60, 20, ESC, &NumRecs, 0,
CharHandlerDemo,
ClearScreenDemo,
DisplayDemo );
}